package com.zb.jsp.action.ajax;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.zb.jsp.service.AdvertAddressService;
import com.zb.jsp.utils.StringUtil;
import com.zb.jsp.vo.AdvertAddressVo;
import com.zb.jsp.vo.advert.AdvertVo;

public class AjaxGetActiveAdvertAction extends ActionSupport {

	//定义返回值的list对象
	List<AdvertVo> advertActiveInfoList ;
	//定义查询service
	AdvertAddressService advertAddressService = new AdvertAddressService();
	//用于接受查询id的变量
	String advertId ;
		
	//定义http请求
	HttpServletRequest request = (HttpServletRequest) ActionContext
    .getContext().get(ServletActionContext.HTTP_REQUEST);
	  
	/**	
	 * 用ajax方法获取活动广告信息
	 * @return 返回成功标志符
	 */
	public String getActiveAdvertInfo(){
		//用于保存返回页面信息的list对象
		advertActiveInfoList = new ArrayList<AdvertVo>();
		//用于接受默认广告信息的vo对象
		AdvertAddressVo advertAddressVo = new AdvertAddressVo();
		
		if(StringUtil.isNullOrEmpty(request.getSession().getAttribute("nameCn"))){
			//若没有用户登陆的话就显示默认广告
			advertAddressVo = advertAddressService.findTblAdvertAddressById(Integer.valueOf(advertId));
			AdvertVo advertVo = new AdvertVo();
			advertVo.setNotes(advertAddressVo.getNotes());
			advertVo.setAdvertPath(advertAddressVo.getDefPath());
			advertActiveInfoList.add(advertVo);
		}else{
			AdvertVo advertVo1 = new AdvertVo();
			advertVo1.setNotes("guag");
			advertVo1.setAdvertPath("banner3.jpg");
			advertActiveInfoList.add(advertVo1);
			
			AdvertVo advertVo2 = new AdvertVo();
			advertVo2.setNotes("guag2");
			advertVo2.setAdvertPath("banner4.jpg");
			advertActiveInfoList.add(advertVo2);
		}
		
		return "getActiveAdvertInfoSuccess";
		
	}

	public List<AdvertVo> getAdvertActiveInfoList() {
		return advertActiveInfoList;
	}

	public void setAdvertActiveInfoList(List<AdvertVo> advertActiveInfoList) {
		this.advertActiveInfoList = advertActiveInfoList;
	}

	public String getAdvertId() {
		return advertId;
	}

	public void setAdvertId(String advertId) {
		this.advertId = advertId;
	}
}
